package net.y2t72.microblog.dao.impl;

import java.util.Map;

import javax.servlet.jsp.jstl.sql.Result;

import net.y2t72.microblog.bean.Buddy;
import net.y2t72.microblog.dao.BuddyDao;
import net.y2t72.microblog.dao.MemberDao;
import net.y2t72.microblog.util.StringUtil;
/**
 * 好友关系表数据访问实现类
 * @author dp
 *
 */

public class BuddyDaoImpl implements BuddyDao {
	
	Buddy buddy = null;
	MemberDao md = new MemberDaoImpl();
	/**
	 * 根据登录用户的ID查询被多少人关注
	 * @param id 
	 * @return
	 * @author dp
	 */
	public int getBuddyNumber1(int id){
		int count = 0;
		String sql = "select count(*) as num from buddy where bubbyId = " + id;
		Result result = BaseDao.getInstance().executeQuery(sql, null);
		if(result.getRowCount() > 0){
			@SuppressWarnings("rawtypes")
			Map map = result.getRows()[0];
			count = StringUtil.parseInt(map.get("num"));
		}
		return count;
	}
	
	/**
	 * 根据登录用户的ID查询关注多少人
	 * @param id
	 * @return
	 * @author dp
	 */
	public int getBuddyNumber2(int id){
		int count = 0;
		String sql = "select count(*) as num from buddy where mid = " + id;
		Result result = BaseDao.getInstance().executeQuery(sql, null);
		if(result.getRowCount() > 0){
			@SuppressWarnings("rawtypes")
			Map map = result.getRows()[0];
			count = StringUtil.parseInt(map.get("num"));
		}
		return count;
	}
	
	/*//根据登录用户的ID查询关注你的人的信息
	public List<Buddy> getBuddyAll1(int id){
		List<Buddy> list = new ArrayList<Buddy>();
		String sql = "select mid from buddy where buddyId =  " + id;
		Result result = BaseDao.getInstance().executeQuery(sql, null);
		for(int i = 0;i < result.getRowCount();i++){
			Map map = result.getRows()[i];
			buddy = new Buddy();
			buddy.setId(StringUtil.parseInt(map.get("id")));
		}
		return null;
	}
	
	//根据登录用户的ID查询所关注人的信息
	public List<Buddy> getBuddyAll2(int id){
		List<Buddy> list = new ArrayList<Buddy>();
		String sql = "select buddyId buddy where mid = " + id;
		return null;
	}*/
}
